package com.gxz.job.example.job;

import java.util.Date;

import org.springframework.stereotype.Component;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;
import com.gxz.job.elasticjob.start.zookeeper.annotation.ElasticSimpleJob;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Component
@ElasticSimpleJob(jobName = "mySimpleJob",corn = "0/20 * * * * ?",
        shardingTotalCount = 4,overwrite = true,failover = true
)
public class MySimpleJob implements SimpleJob {
    @SneakyThrows
    @Override
    public void execute(ShardingContext shardingContext) {
        log.info("作业开始执行");
        //Thread.sleep(15000);
        int totalCount = shardingContext.getShardingTotalCount(); //分片总数量
        int item = shardingContext.getShardingItem();//当前分片
        log.info("作业任务被执行了" + new Date() + "总分片数量" + totalCount + "当前分片:" + item);
    }
}
